package com.fastPlat.scheduled;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import com.alibaba.rocketmq.common.message.MessageExt;

@Component("messageListener")
public class MessageListenerImpl implements MessageListenerConcurrently {
	
	@Value("${rocketMQ-topic}")
	private String topic;
	
	@Value("${rocketMQ-tags}")
	private String tag;

	@Override
	public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
		try {
			System.out.println("MessageExt size:"+msgs.size());
			MessageExt messageExt = msgs.get(0);
			System.out.println("监听器到内容："+messageExt);
			// TODO 执行Topic的消费逻辑
			if (messageExt.getTags() != null && messageExt.getTags().equals(tag)) {
				// TODO 执行Tag的消费
				String userStr = new String(messageExt.getBody());
				System.out.println("接收到的信息："+userStr);
			}
			return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ConsumeConcurrentlyStatus.RECONSUME_LATER;
		
	}

}
